package com.iot.comprehensive.face.service.impl;

import com.iot.comprehensive.face.dao.UserDao;
import com.iot.comprehensive.face.model.User;
import com.iot.comprehensive.face.service.UserService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @Author 朱泽玉
 * @Create 2021/6/26 12:21
 * @Description
 * @Modified By:
 */
@Service
public class UserServiceImpl implements UserService{

    final UserDao userDao;

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void update(User user) {
        add(user);
//        User user_info = userDao.findById(user.getId()).orElse(null);
//        assert user_info != null;
//        user_info.setAddress(user.getAddress());
//        user_info.setAge(user.getAge());
//        user_info.setDescription(user.getDescription());
//        user_info.setSex(user.getSex());
//        user_info.setLast_time(user.getLast_time());
//        user_info.setName(user.getName());
//        user_info.setId(user.getId());
//        userDao.save(user_info);
    }

    @Override
    public void delete(Long id) {
        userDao.deleteById(id);
    }

    @Override
    public User getByAccount(Long id) {
        return userDao.findById(id).orElse(null);
    }

    @Override
    public void add(User user) {
        userDao.save(user);
    }

    @Override
    public User getOne(Long id) {
        return userDao.findById(id).orElse(null);
    }

    @Override
    public List<User> getAll() {
        return userDao.findAll();
    }
}
